
package com.hlkj.pay.controller.devices;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.Collections;
import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.pay.app.devices.IMerchantQrTemplateAppService;
import com.hlkj.pay.controller.BaseController;
import com.hlkj.pay.infrastructure.model.devices.MerchantQrTemplateDO;
import com.hlkj.pay.service.devices.IMerchantQrTemplateService;
import com.hlkj.pay.vo.BasePageReq;
import com.hlkj.pay.vo.devices.req.MerchantQrTemplateReq;
import com.hlkj.pay.vo.devices.resp.MerchantQrTemplateResp;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

/**
 * @author HlpayTeam
 * @date 2025/01/20 11:03
 */
@Tag(name = "码牌模板管理")
@RestController
@RequestMapping("/v1/merchant/qr/template")
@RequiredArgsConstructor
public class MerchantQrTemplateController extends BaseController {

    private final IMerchantQrTemplateService merchantQrTemplateService;

    private final IMerchantQrTemplateAppService merchantQrTemplateAppService;

    @Operation(summary = "码牌模板列表分页")
    @GetMapping("/page")
    CommonResult<PageResult<MerchantQrTemplateResp>> queryPage(@Validated BasePageReq basePageReq) {
        PageResult<MerchantQrTemplateDO> page = merchantQrTemplateService.queryPage(basePageReq);
        List<MerchantQrTemplateDO> list = page.getList();
        if (CollectionUtils.isEmpty(list)) {
            return buildPageResult(page, Collections.emptyList());
        }
        List<MerchantQrTemplateResp> merchantInfoPageResps = BeanUtil.copyToList(list, MerchantQrTemplateResp.class);
        return buildPageResult(page, merchantInfoPageResps);
    }

    @Operation(summary = "码牌模板列表")
    @GetMapping("/list")
    CommonResult<List<MerchantQrTemplateResp>> queryList(@Validated BasePageReq basePageReq) {
        List<MerchantQrTemplateDO> list = merchantQrTemplateService.queryList(basePageReq);
        if (CollectionUtils.isEmpty(list)) {
            return CommonResult.success(Collections.emptyList());
        }
        List<MerchantQrTemplateResp> merchantAppResps = BeanUtil.copyToList(list, MerchantQrTemplateResp.class);
        return CommonResult.success(merchantAppResps);
    }

    @Operation(summary = "码牌模板保存")
    @PostMapping("")
    CommonResult<Void> saveTemplate(@Validated @RequestBody MerchantQrTemplateReq basePageReq) {
        return merchantQrTemplateAppService.saveTemplate(basePageReq);
    }

    @Operation(summary = "码牌模板更新")
    @PutMapping("")
    CommonResult<Void> updateTemplate(@Validated @RequestBody MerchantQrTemplateReq basePageReq) {
        return merchantQrTemplateAppService.saveTemplate(basePageReq);
    }
}
